import { Module } from 'vuex';
import { METAINFO_ACTION, SET_METAINFO, GET_METAINFO, STORAGE_METAINFO } from '@/utils/Const';
import Storage from '@/utils/Storage';
import { IGlobalDataProps } from '../index';

export interface IMetaInfoProps {
	title?: string;
	hasFooter?: boolean;
}

let metaInfo: Module<IMetaInfoProps, IGlobalDataProps> = {
	namespaced: true,
	state: {
		title: '',
		hasFooter: true,
		...(Storage.get<IMetaInfoProps>(STORAGE_METAINFO, 1) || {}),
	},
	getters: {
		[GET_METAINFO](state: IMetaInfoProps) :IMetaInfoProps {
			return state;
		},
	},
	mutations: {
		[SET_METAINFO](state: IMetaInfoProps, payload: IMetaInfoProps) :void {
			state = payload;
			Storage.set<IMetaInfoProps>(STORAGE_METAINFO, payload, 1);
		},
	},
	actions: {
		[METAINFO_ACTION]({ commit }, payload: IMetaInfoProps) :void {
			commit(SET_METAINFO, payload);
		},
	},
};

export default metaInfo;
